<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="compQuery.name" placeholder="比赛名" />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()"
        >查询</el-button
      >
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <el-table
      :data="list"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="比赛名"  />
      
      <el-table-column prop="location" label="比赛地点"  />

      <el-table-column prop="time" label="比赛时间" />

      <el-table-column prop="maxNum" label="最大人数" />

      <el-table-column prop="nowNum" label="报名人数" />

      <el-table-column prop="gmtCreate" label="创建时间" />

      <el-table-column label="操作"  align="center" width="400">
        <template slot-scope="scope">

          <router-link :to="'/comp/update/' + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-paperclip"
              >进入比赛</el-button
            >
          </router-link>

             
          <router-link :to="'/comp/update/' + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"
              >修改</el-button
            >
          </router-link>

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="deleteEvent(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
        <!-- 分页 -->
    <el-pagination
      :current-page="this.page"
      :page-size="this.limit"
      :total="this.total"
      style="padding: 30px 0; text-align: center"
      layout="total, prev, pager, next, jumper"
      @current-change="this.getList"
    />
  </div>
</template>

<script>
import comp from '@/api/comp/comp'
export default {
  // data:{

  // },
  data() {
    return {
      list: null,
      page: 1,
      limit: 8,
      total: 0,
      compQuery: {},
    };
  },
  created() {
      this.getList()
  },
  methods: {
      getList(page = 1) {
        this.page = page;
        console.log(this.page);
        comp.getCompList(this.page,this.limit,this.compQuery).
        then((response) => {
          this.list = response.data.records
          this.total = response.data.total
        })
        .catch((error) => {
          console.log(error)
        });
      },
      resetData() {
        this.eventQuery = {}
        this.getList()
      },
      //删除方法
      deleteEvent(id) {
        this.$confirm("此操作将永久删除项目记录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          comp
            .deleteComp(id)
            .then((response) => {
              this.getList();
            })
            .catch((error) => {});
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        });
      },
  },
};
</script>